<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" import="service.ErrorService"
	import="dto.TournamentDTO"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%
	ErrorService error = (ErrorService) request.getAttribute("error");
%>
<%
	TournamentDTO tDTO = (TournamentDTO) request
			.getAttribute("Tournament");
%>
<%
	Integer teamCount = (Integer) request.getAttribute("teamCount");
%>
<%
	Boolean organisor = (Boolean) request.getAttribute("organisor");
%>

<%
	if (error != null)
		out.println(error.getError());
%>

<%
	String format = "";
	switch (tDTO.getFormat()) {
	case 1:
		format = "Single Elimination";
		break;
	case 2:
		format = "Double Elimination";
		break;
	}
%>

<%
	String type = "";
	switch (tDTO.getType()) {
	case 0:
		type = "Open";
		break;
	case 1:
		type = "Invitational";
		break;
	}
%>

<%
	String status = "";
	switch (tDTO.getStatus()) {
	case 0:
		status = "Not started";
		break;
	case 1:
		status = "Started";
		break;
	case 2:
		status = "Finished";
		break;
	}
%>

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Edit Team</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="css/bootstrap.css" rel="stylesheet">
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<style type="text/css"></style>
</head>

<body>
	<div class="container">
		<div class="header">
			<ul class="nav nav-pills pull-right">
				<%@include file="/WEB-INF/user/menu.jsp"%>
			</ul>
			<h2 class="text-muted">Tournament Hosting</h2>
			<hr>
		</div>
	</div>

	<div class="container" style="padding-bottom: 2px">

		<div class="list-group col-md-6 ">
			<%
				if (error != null)
					out.println(error.getError());
			%>
		</div>
	</div>

	<div class="container" style="padding-bottom: 2px">
		<div class="list-group col-md-6 ">
			<button class="btn btn-primary btn-sm" data-toggle="modal" data-target="#addModal">Add Team</button>
			<button class="btn btn-primary btn-sm" data-toggle="modal" data-target="#removeModal">Remove Team</button>
			<button class="btn btn-primary btn-sm" data-toggle="modal" data-target="#editModal">Edit Tournament</button>
			<button class="btn btn-primary btn-sm" data-toggle="modal" data-target="#deleteTourModal">Delete Tournament</button>
			<button class="btn btn-primary btn-sm" data-toggle="modal" data-target="#startModal">Start/Finish Tournament</button>
		</div>
		<div class="pull-right ">
			<!--                 <button class="btn-sm btn-primary">Start Tournament</button> -->
		</div>
	</div>

	<div class="container" style="padding-top: 52px">
		<div>
			<table class="table table-bordered">
				<thead>
					<th>Tournament Name</th>
					<th>Sport</th>
					<th>Type</th>
					<th>Format</th>
					<th>Starting Date</th>
					<th>Participants</th>
					<th>Status</th>
				</thead>
				<tbody>
					<tr>
						<td>
							<%
								out.print(tDTO.getTournamentName());
							%>
						</td>
						<td>
							<%
								out.print(tDTO.getSport());
							%>
						</td>
						<td>
							<%
								out.print(type);
							%>
						</td>
						<td>
							<%
								out.print(format);
							%>
						</td>
						<td>
							<%
								out.print(tDTO.getStartDate());
							%>
						</td>
						<td>
							<%
								out.print(teamCount + " / " + tDTO.getMaxParticipants());
							%>
						</td>
						<td>
							<%
								out.print(status);
							%>
						</td>
					</tr>
				</tbody>
			</table>
		</div>
	</div>

	<div class="container">
		<div class="col-md-6" style="padding-bottom: 20px">
			<%
				if (request.getAttribute("placementList") != null) {
					out.print("<h2>Placementlist</h2>");
					out.print("<div id=\"inner-content-div\">");
					out.print("<ul>");
					out.print(request.getAttribute("placementList"));
					out.print("</ul>");
					out.print("</div>");
				} else {
					out.print("<h2>Participants</h2>");
					out.print("<div id=\"inner-content-div\">");
					out.print("<ul>");
					out.print(request.getAttribute("teamList"));
					out.print("</ul>");
					out.print("</div>");
				}
			%>
		</div>
		<div class="col-md-6">
			<h2>Tournament Info</h2>
			<p>
				<%
					out.print(tDTO.getInfo());
				%>
			</p>
		</div>
	</div>

	<%
		if (error != null) {
			out.print("<div class=\"col-md-4 well\" id=\"content\">");
			out.println(error.getError());
			out.print("</div>");
		}
	%>





	<!-- Modal -->
	<div class="modal fade" id="addModal" tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true">&times;</button>
					<h4 class="modal-title">Add Team</h4>
				</div>
				<div class="modal-body">
					<form method="POST" action="TournamentManager">
						<label>Team name</label> <input class="form-control" type="text"
							name="name"> <br> <input type="hidden" name="action"
							value="add team"> <input type="hidden"
							class="form-control" name="id" value="<%=tDTO.getId()%>">
						<button type="submit" class="btn btn-lg btn-primary">Add
							Team</button>
					</form>
				</div>
			</div>
			<!-- /.modal-content -->
		</div>
		<!-- /.modal-dialog -->
	</div>
	<!-- /.modal -->
	<!-- Modal -->

	<!-- Modal -->
	<div class="modal fade" id="startModal" tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true">&times;</button>
					<h4 class="modal-title">Start/Finish</h4>
				</div>
				<div class="modal-body">
					<form method="POST" action="TournamentManager">
						<input type="hidden" name="action" value="StartFinish"> <input
							type="hidden" class="form-control" name="id"
							value="<%=tDTO.getId()%>">
						<button type="submit" class="btn btn-lg btn-primary">Start/Finish</button>
					</form>
				</div>
			</div>
			<!-- /.modal-content -->
		</div>
		<!-- /.modal-dialog -->
	</div>
	<!-- /.modal -->
	<!-- Modal -->

	<div class="modal fade" id="removeModal" tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel" aria-hidden="true">

		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true">&times;</button>
					<h4 class="modal-title">Remove Team</h4>
				</div>
				<div class="modal-body">
					<form method="POST" action="TournamentManager">
						<label>Team name</label> <input class="form-control" type="text"
							name="name"> <br> <input type="hidden" name="action"
							value="delete team"> <input type="hidden"
							class="form-control" name="id" value="<%=tDTO.getId()%>">
						<button type="submit" class="btn btn-lg btn-primary">Remove
							team</button>
					</form>
				</div>
			</div>
			<!-- /.modal-content -->
		</div>
		<!-- /.modal-dialog -->
	</div>
	<!-- /.modal -->
	<!-- Modal -->
	<div class="modal fade" id="editModal" tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true">&times;</button>
					<h4 class="modal-title">Edit Tournament</h4>
				</div>
				<div class="modal-body">
					<form class="form-signin" method="POST" action="TournamentManager">
						<label> Tournament Name</label> <input type="text"
							class="form-control" name="tournament_name"
							value="<%=tDTO.getTournamentName()%>"> <br> <label>Sport</label>
						<select class="form-control" name="Sport">
							<option value="" disabled selected>Please select a sport</option>
							<option value="soccer">Soccer</option>
							<option value="tennis">Tennis</option>
							<option value="pool">Pool</option>
						</select> <br> <label>Tournament Format</label> <select
							class="form-control" name="Tournament Format">
							<option value="" disabled selected>Please select a
								format</option>
							<option value="format1">Single Elimination</option>
							<option value="format2">Double Elimination</option>
						</select> <br> <label>Tournament Type</label> <select
							class="form-control" name="Tournament Type">
							<option value="" disabled selected>Please select a type</option>
							<option value="type1">Open</option>
							<option value="type2">Invitation</option>
						</select> <br> <label>Participant Count</label> <input type="text"
							class="form-control" name="size"
							value="<%=tDTO.getMaxParticipants()%>"> <br> ' <label>Starting
							Date</label> <input type="text" class="form-control" name="Starting Date"
							value="<%=tDTO.getStartDate()%>"> <br> <label>Info</label>
						<input type="text" class="form-control" name="info"
							value="<%=tDTO.getInfo()%>"> <br>
						<button class="btn btn-lg btn-primary " type="submit">Edit</button>
						<input type="hidden" class="form-control" name="action"
							value="edit tournament"> <input type="hidden"
							class="form-control" name="id" value="<%=tDTO.getId()%>">
					</form>
				</div>
			</div>
			<!-- /.modal-content -->
		</div>
		<!-- /.modal-dialog -->
	</div>
	<!-- /.modal -->
	<!-- Modal -->
	<div class="modal fade" id="deleteTourModal" tabindex="-1"
		role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true">&times;</button>
					<h4 class="modal-title">Delete Tournament</h4>
				</div>
				<div class="modal-body">
					<form method="POST" action="TournamentManager">
						<input type="hidden" class="form-control" name="action"
							value="delete tournament"> <input type="hidden"
							class="form-control" name="id" value="<%=tDTO.getId()%>">
						<label class="form-control">Are you sure?</label> <br>
						<button class="btn btn-success btn-lg" data-dismiss="modal">No</button>
						<button class="btn btn-lg btn-danger " type="submit">Yes</button>
					</form>
				</div>
			</div>
			<!-- /.modal-content -->
		</div>
		<!-- /.modal-dialog -->
	</div>
	<!-- /.modal -->

</body>

</html>